package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {
    /**
     * 根据categoryId查询1关联的套餐数
     * @param categoryId
     */
    @Select("select count(*) from setmeal where category_id=#{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 新增套餐
     * @param setmeal
     */
    @AutoFill(value = OperationType.INSERT)
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into setmeal (category_id, name, price, description, image, create_time, update_time, create_user, update_user) VALUES " +
            "(#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void insert(Setmeal setmeal);
    /**
     * 套餐分页查询
     * @param setmealPageQueryDTO
     */
    Page pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 更新套餐信息
     * @param setmeal
     */
    void update(Setmeal setmeal);
    /**
     * 根据id删除套餐
     * @param id
     */
    @Delete("delete from setmeal where id=#{id}")
    void deleteById(Long id);
    /**
     * 根据id查询套餐
     * @param id
     */
    @Select("select * from setmeal where id=#{id};")
    Setmeal selectById(Long id);
    @Select("select * from setmeal where category_id=#{categoryId}")
    List<Setmeal> selectByCategoryId(Long categoryId);

    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
